package demo1;

import java.util.Scanner;

/**
 * @Author liangzai
 * @Description:
 */
public class Training {
    //最大子矩阵
    public static void main1(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String[] strings = new String[21];
        int[][] nums = new int[21][21];
        strings[1] = "69859241839387868941";strings[2] = "17615876963131759284";strings[3] = "37347348326627483485";strings[4] = "53671256556167864743";strings[5] = "16121686927432329479";
        strings[6] = "13547413349962773447";strings[7] = "27979945929848824687";strings[8] = "53776983346838791379";strings[9] = "56493421365365717745";strings[10] = "21924379293872611382";
        strings[11] = "93919353216243561277";strings[12] = "54296144763969257788";strings[13] = "96233972513794732933";strings[14] = "81443494533129939975";strings[15] = "61171882988877593499";
        strings[16] = "61216868895721348522";strings[17] = "55485345959294726896";strings[18] = "32124963318242554922";strings[19] = "13593647191934272696";strings[20] = "56436895944919899246";
        for (int j = 1; j <= 20; j++) {
            for (int i = 0; i < 20; i++) {
                nums[j][i+1] = Integer.valueOf(strings[j].charAt(i))-48;
            }
        }
        int max = 0;
        int sum = 0;
        for (int i = 5; i <= 20; i++) {
            for (int j = 5; j <= 20; j++) {
                sum = 0;
                for (int n = i-4; n <= i; n++) {
                    for (int m = j-4; m <= j; m++) {
                        sum += nums[n][m];
                    }
                }
                max = Math.max(sum, max);
            }
        }
        System.out.println(max);
//		for (int i = 1; i <= 20; i++) {
//
//			for (int j = 1; j <= 20; j++) {
//
//			}
//		}
    }

    //数组切分
    public static void main(String[] args) {
        int mod = 1000000007;
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int[] nums = new int[n+1];
        for (int i = 1; i <= n; i++) {
            nums[i] = scanner.nextInt();
        }
        int[] dp = new int[n+1];
        dp[0] = 1;
        for (int i = 1; i <= n; i++) {
            int max = Integer.MIN_VALUE;
            int min = Integer.MAX_VALUE;
            for (int j = i; j > 0; j--) {
                max = Math.max(max, nums[j]);
                min = Math.min(min, nums[j]);
                if((max-min)==(i-j)) {
                    dp[i] = (dp[i]+dp[j-1])%1000000007;
                }
            }
        }
        System.out.println(dp[n]);
    }

    static int mod = 1000000007;
    public static void main2(String[] args) {
        Scanner scan=new Scanner(System.in);
        int n=scan.nextInt();
        int[] a=new int[n+1];
        for (int i=1;i<=n;i++) a[i]=scan.nextInt();
        //dp[i]：以a[i]结尾的切分合法数组的方法数量
        int[] dp=new int[n+1];
        dp[0]=1;//初始化
        for (int i=1;i<=n;i++){
            int max=Integer.MIN_VALUE,min=Integer.MAX_VALUE;//注意初始化：max是小的，min是大的
            for (int j=i;j>0;j--){
                max =Math.max(max,a[j]);
                min =Math.min(min,a[j]);
                if (max-min==i-j) dp[i]=(dp[i]+dp[j-1])%mod;

            }
        }
        System.out.println(dp[n]);
    }
}
